<?php

namespace app\common\model;

use think\Paginator;

class ShoppingSku extends BaseModel
{
    protected $name = 'shopping_sku';

    /**
     * 获取数据列表
     * @return Paginator
     */
    public function getList(): Paginator
    {
        return $this->order('_id', 'desc')
            ->paginate($this->pageLimit);
    }

    /**
     * 添加数据
     * @param array $data
     * @return string
     */
    public function addData(array $data): string
    {
        //添加时销毁自带的主键id
        unset($data['id']);
        return $this->save($data);
    }

    /**
     * 更新数据
     * @param array $data
     * @return bool
     */
    public function saveData($id, array $data): bool
    {
        $model = self::find($id);
        return $model->save($data);
    }
}